/**
 * author:Administrator
 * date:2016/2/25
 * desc:TODO
 */

'use strict';

let Repo = require('./customerRepo.js');

class Customer {

  /**
   * 从数据库中读取，re-constructor an obj
   * @param pojo
   */
  static rebuild(pojo) {
    let entity = new Customer();
    let keys = Object.keys(pojo);
    for (let key of keys) {
      entity[key] = pojo[key];
    }
    return entity;
  }

  /**
   * 新建 一个当前对象的实例
   * @param pojo, key:
   */
  static freshNew(pojo) {
    let entity = new Customer();
    if (pojo.uId) entity.uId = pojo.uId;
    entity.name = pojo.name;
    return entity;
  }

  * store() {
    return yield Repo.store(this);
  }

}

module.exports = Customer;